package com.gxa.shop.servlet.cart;

import com.alibaba.fastjson.JSON;
import com.gxa.shop.bean.vo.CartVo;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.service.cart.CartService;
import com.gxa.shop.service.cart.Impl.CartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * com.gxa.shop.servlet.cart
 * User: 刁彦侨
 * Date: 2024/12/19 15:57
 * motto:   逆水行舟不进则退
 * Description:
 * Version: V1.0
 */
@WebServlet(name = "cart.FindByIdServlet" ,value = "/cart/findById")
public class FindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        CartService cartService = new CartServiceImpl();
        List<CartVo> cartList = cartService.findById(id);
        R r= R.ok(cartList);
        PrintWriter writer = response.getWriter();
        String result = JSON.toJSONString(r);
        System.out.println("cart.FindByIdServlet后台:"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}
